﻿#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

//1. C / C++内存分布
int globalVar = 1;
static int staticGlobalVar = 1;
void Test() {
	static int staticVar = 1;
	int localVar = 1;
	int num1[10] = { 1, 2, 3, 4 };
	char char2[] = "abcd";
	const char* pChar3 = "abcd";
	int* ptr1 = (int*)malloc(sizeof(int) * 4);
	int* ptr2 = (int*)calloc(4, sizeof(int));
	int* ptr3 = (int*)realloc(ptr2, sizeof(int) * 4);
	free(ptr1);
	free(ptr3);
}
//1. 选择题：
//选项 : A.栈  B.堆  C.数据段(静态区)  D.代码段(常量区)
//globalVar在哪里？C 		staticGlobalVar在哪里？C
//staticVar在哪里？C  	localVar在哪里？A
//num1 在哪里？A
//
//char2在哪里？A			*char2在哪里？A   char2是数组，它把常量区的abcd\0拷贝到数组中
//pChar3在哪里？A		*pChar3在哪里？D  pChar3是指针，指向常量区的数据
//ptr1在哪里？A			*ptr1在哪里？B

//2. 填空题：
//sizeof(num1) = 40;
//sizeof(char2) = 5;      	strlen(char2) = 4;
//sizeof(pChar3) = 4/8;     strlen(pChar3) = 4;
//sizeof(ptr1) = 4/8;